package com.tlvip.design.decorator;

/**
 * <p>description：</p>
 * <p>
 * 在不改变原有对象的基础上，将功能附加到对象上，对修改关闭，对拓展开放
 *
 * 优点
 *  不改变原有对象的情况下，给一个对象扩展功能
 *  使用不同的组合可以实现不同的效果
 *  符合开闭原则
 *
 * JDK
 *  Servlet Api
 *  HttpServletRequest
 *  ServletRequestWrapper
 *
 * <p>copyright： copyright(C)2016-2099</p>
 * <p>Life is short,we need passion</p>
 * <p>Summary： </p>
 * <p>instructions： </p>
 * Date 2021/8/14</p>
 * Author mac
 *
 * @version 1.0
 */
public class TestDecorator {
    public static void main(String[] args) {

        // 原始调用方法
        /*Component component = new ConcreteComponent();
        component.operation();*/

        // 增加美颜，装饰
//        Component component = new ConcreteDecorator1(new ConcreteComponent());
//        component.operation();

        // 增加滤镜
        Component component = new ConcreteDecorator2(new ConcreteDecorator1(new ConcreteComponent()));
        component.operation();


    }
}

interface Component {
    void operation();
}

class ConcreteComponent implements Component {

    @Override
    public void operation() {
        System.out.println("拍照 ");
    }
}

// 封装与继承 完成装饰模式
abstract class Decorator implements Component {
    Component component;

    public Decorator(Component component) {
        this.component = component;
    }
}

class ConcreteDecorator1 extends Decorator {

    public ConcreteDecorator1(Component component) {
        super(component);
    }

    @Override
    public void operation() {
        System.out.println("添加美颜");
        component.operation();
    }
}

class ConcreteDecorator2 extends Decorator {

    public ConcreteDecorator2(Component component) {
        super(component);
    }

    @Override
    public void operation() {
        System.out.println("添加滤镜");
        component.operation();
    }
}